/**
 * 题目链接：2025/10/03 考试
 * 完成时间: 2025-10-03 11:45
 * 简要思路：维护直径。
 */
#include <bits/stdc++.h>
#define range(i, b, e) for (auto i(b); i != (e); i++)
#define rep(i, b, e) for (auto i(b); i <= (e); i++)
#define req(i, b, e) for (auto i(b); i >= (e); i--)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> Pii;

const int N = 2e5;
int ID;
int n, ans;
int fa[N+5], dep[N+5], len[N+5];
vector<int> son[N+5];

void upd(int u) {
	int R = 0;
	len[u] = 0;
	for (int v: son[u]) {
		R = max(R, len[u] + 1 + len[v]);
		len[u] = max(len[u], len[v] + 1);
	}
	ans = max(ans, R + dep[u]);
}

int main() {
	freopen("forest.in", "r", stdin);
	freopen("forest.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> ID >> n;
	rep(i, 2, n) {
		cin >> fa[i];
		fa[i] ^= ans;
		dep[i] = dep[fa[i]] + 1;
		son[fa[i]].emplace_back(i);
		for (int u = i; u; u = fa[u]) upd(u);
		cout << ans << '\n';
	}
	return 0;
}
